package ma.ensias.healthme.admin;

import java.io.Serializable;

import ma.ensias.healthme.R;
import ma.ensias.healthme.dao.PersonneDao;
import ma.ensias.healthme.dao.PointTraitDao;
import ma.ensias.healthme.entities.Personne;
import ma.ensias.healthme.entities.PointTrait;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class InfoPTActivity extends FragmentActivity {

	PointTrait p;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_info_pt);
		
		p=(PointTrait)getIntent().getSerializableExtra("pt");
	
		TextView li=(TextView)findViewById(R.id.Libelle);
		TextView ad=(TextView)findViewById(R.id.Adresse);
		TextView lon=(TextView)findViewById(R.id.Longitude);
		TextView la=(TextView)findViewById(R.id.Latitude);
		
		if(p!=null){
			li.setText(p.getLibelle());
			ad.setText(p.getAdresse());
			lon.setText(Float.toString(p.getLongitude()));
			la.setText(Float.toString(p.getLatitude()));
			
		}
		
		Button retour = (Button) findViewById(R.id.button3);
		
		retour.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	retour();
                
            }

        });
		
		Button supprimer = (Button) findViewById(R.id.button2);
		
		supprimer.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	showDialog();
            }
        });
		
		Button modifier = (Button) findViewById(R.id.button1);
		
		modifier.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	modifierPT();
            }
        });
        
       
	}

	
	void modifierPT(){
		Intent i=new Intent(this,ModifierPTActivity.class);
		i.putExtra("pt", (Serializable)p);
		startActivity(i);
		finish();
	}
	
	
	void showDialog() {
        DialogFragment newFragment = MyAlertDialogFragment1
                .newInstance(R.string.confirmation);
        newFragment.show(getSupportFragmentManager(),"dialog");
    }

    public void doPositiveClick() {
    	PointTraitDao dao=new PointTraitDao();
    	dao.delete(p.getId());
    	startActivity(new Intent(this, ListPTActivity1.class));
    	finish();
    }

    public void doNegativeClick() {
        // Do stuff here.
    	finish();
        Log.i("FragmentAlertDialog", "Negative click!");
    }
	
	
	void retour(){
		startActivity(new Intent(this,ListPTActivity1.class));
    	finish();
	}
	
	
	/*public void finish() {
		/*finish();
		startActivity(new Intent(this,ListComptesActivity.class));
		InfoCompteActivity.this.finish();
		
	 }*/
}
